home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / CIncludes / DatabaseAccess.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  12.6 KB  |  366 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        DatabaseAccess.h
  3.  
  4.      Contains:    Database Access Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.0.1
  8.  
  9.      Copyright:    © 1989-1993, 1995-1997 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __DATABASEACCESS__
  19. #define __DATABASEACCESS__
  20.  
  21. #ifndef __RESOURCES__
  22. #include <Resources.h>
  23. #endif
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. /* data type codes */
  48.  
  49. enum {
  50.     typeNone                    = FOUR_CHAR_CODE('none'),
  51.     typeDate                    = FOUR_CHAR_CODE('date'),
  52.     typeTime                    = FOUR_CHAR_CODE('time'),
  53.     typeTimeStamp                = FOUR_CHAR_CODE('tims'),
  54.     typeDecimal                    = FOUR_CHAR_CODE('deci'),
  55.     typeMoney                    = FOUR_CHAR_CODE('mone'),
  56.     typeVChar                    = FOUR_CHAR_CODE('vcha'),
  57.     typeVBin                    = FOUR_CHAR_CODE('vbin'),
  58.     typeLChar                    = FOUR_CHAR_CODE('lcha'),
  59.     typeLBin                    = FOUR_CHAR_CODE('lbin'),
  60.     typeDiscard                    = FOUR_CHAR_CODE('disc'),        /* "dummy" types for DBResultsToText */
  61.     typeUnknown                    = FOUR_CHAR_CODE('unkn'),
  62.     typeColBreak                = FOUR_CHAR_CODE('colb'),
  63.     typeRowBreak                = FOUR_CHAR_CODE('rowb'),        /* pass this in to DBGetItem for any data type */
  64.     typeAnyType                    = 0
  65. };
  66.  
  67. /* infinite timeout value for DBGetItem */
  68.  
  69. enum {
  70.                                                                 /* messages for status functions for DBStartQuery */
  71.     kDBUpdateWind                = 0,
  72.     kDBAboutToInit                = 1,
  73.     kDBInitComplete                = 2,
  74.     kDBSendComplete                = 3,
  75.     kDBExecComplete                = 4,
  76.     kDBStartQueryComplete        = 5
  77. };
  78.  
  79.  
  80. enum {
  81.                                                                 /* messages for status functions for DBGetQueryResults */
  82.     kDBGetItemComplete            = 6,
  83.     kDBGetQueryResultsComplete    = 7,
  84.     kDBWaitForever                = -1
  85. };
  86.  
  87.  
  88. enum {
  89.                                                                 /*  flags for DBGetItem  */
  90.     kDBLastColFlag                = 0x0001,
  91.     kDBNullFlag                    = 0x0004
  92. };
  93.  
  94. typedef OSType                             DBType;
  95. typedef struct DBAsyncParamBlockRec     DBAsyncParamBlockRec;
  96. typedef DBAsyncParamBlockRec *            DBAsyncParmBlkPtr;
  97. typedef CALLBACK_API( void , DBCompletionProcPtr )(DBAsyncParmBlkPtr pb);
  98. /*
  99.     WARNING: DBCompletionProcPtr uses register based parameters under classic 68k
  100.              and cannot be written in a high-level language without 
  101.              the help of mixed mode or assembly glue.
  102. */
  103. typedef REGISTER_UPP_TYPE(DBCompletionProcPtr)                     DBCompletionUPP;
  104. /* structure for asynchronous parameter block */
  105. struct DBAsyncParamBlockRec {
  106.     DBCompletionUPP                 completionProc;                /* pointer to completion routine */
  107.     OSErr                             result;                        /* result of call */
  108.     long                             userRef;                    /* for application's use */
  109.     long                             ddevRef;                    /* for ddev's use */
  110.     long                             reserved;                    /* for internal use */
  111. };
  112.  
  113. /* structure for resource list in QueryRecord */
  114. struct ResListElem {
  115.     ResType                         theType;                    /* resource type */
  116.     short                             id;                            /* resource id */
  117. };
  118. typedef struct ResListElem ResListElem;
  119.  
  120. typedef ResListElem *                    ResListPtr;
  121. typedef ResListPtr *                    ResListHandle;
  122. /* structure for query list in QueryRecord */
  123. typedef Handle                             QueryArray[256];
  124. typedef Handle *                        QueryListPtr;
  125. typedef QueryListPtr *                    QueryListHandle;
  126. struct QueryRecord {
  127.     short                             version;                    /* version */
  128.     short                             id;                            /* id of 'qrsc' this came from */
  129.     Handle                             queryProc;                    /* handle to query def proc */
  130.     Str63                             ddevName;                    /* ddev name */
  131.     Str255                             host;                        /* host name */
  132.     Str255                             user;                        /* user name */
  133.     Str255                             password;                    /* password */
  134.     Str255                             connStr;                    /* connection string */
  135.     short                             currQuery;                    /* index of current query */
  136.     short                             numQueries;                    /* number of queries in list */
  137.     QueryListHandle                 queryList;                    /* handle to array of handles to text */
  138.     short                             numRes;                        /* number of resources in list */
  139.     ResListHandle                     resList;                    /* handle to array of resource list elements */
  140.     Handle                             dataHandle;                    /* for use by query def proc */
  141.     long                             refCon;                        /* for use by application */
  142. };
  143. typedef struct QueryRecord QueryRecord;
  144.  
  145. typedef QueryRecord *                    QueryPtr;
  146. typedef QueryPtr *                        QueryHandle;
  147. /* structure of column types array in ResultsRecord */
  148. typedef DBType                             ColTypesArray[256];
  149. typedef Handle                             ColTypesHandle;
  150. /* structure for column info in ResultsRecord */
  151. struct DBColInfoRecord {
  152.     short                             len;
  153.     short                             places;
  154.     short                             flags;
  155. };
  156. typedef struct DBColInfoRecord DBColInfoRecord;
  157.  
  158. typedef DBColInfoRecord                 ColInfoArray[256];
  159. typedef Handle                             ColInfoHandle;
  160. /* structure of results returned by DBGetResults */
  161. struct ResultsRecord {
  162.     short                             numRows;                    /* number of rows in result */
  163.     short                             numCols;                    /* number of columns per row */
  164.     ColTypesHandle                     colTypes;                    /* data type array */
  165.     Handle                             colData;                    /* actual results */
  166.     ColInfoHandle                     colInfo;                    /* DBColInfoRecord array */
  167. };
  168. typedef struct ResultsRecord ResultsRecord;
  169.  
  170.  
  171. enum {
  172.                                                                 /* messages sent to a 'ddev'*/
  173.     kDBInit                        = 0,
  174.     kDBEnd                        = 1,
  175.     kDBGetConnInfo                = 2,
  176.     kDBGetSessionNum            = 3,
  177.     kDBSend                        = 4,
  178.     kDBSendItem                    = 5,
  179.     kDBExec                        = 6,
  180.     kDBState                    = 7,
  181.     kDBGetErr                    = 8,
  182.     kDBBreak                    = 9,
  183.     kDBGetItem                    = 10,
  184.     kDBUngetItem                = 11,
  185.     kDBKill                        = 12,
  186.     kDBOpen                        = 100,
  187.     kDBClose                    = 101,
  188.     kDBIdle                        = 102
  189. };
  190.  
  191. typedef CALLBACK_API( OSErr , DBQueryDefProcPtr )(long *sessID, QueryHandle query);
  192. typedef CALLBACK_API( Boolean , DBStatusProcPtr )(short message, OSErr result, short dataLen, short dataPlaces, short dataFlags, DBType dataType, Ptr dataPtr);
  193. typedef CALLBACK_API( OSErr , DBResultHandlerProcPtr )(DBType dataType, short theLen, short thePlaces, short theFlags, Ptr theData, Handle theText);
  194. typedef STACK_UPP_TYPE(DBQueryDefProcPtr)                         DBQueryDefUPP;
  195. typedef STACK_UPP_TYPE(DBStatusProcPtr)                         DBStatusUPP;
  196. typedef STACK_UPP_TYPE(DBResultHandlerProcPtr)                     DBResultHandlerUPP;
  197. enum { uppDBCompletionProcInfo = 0x0000B802 };                     /* register no_return_value Func(4_bytes:A1) */
  198. enum { uppDBQueryDefProcInfo = 0x000003E0 };                     /* pascal 2_bytes Func(4_bytes, 4_bytes) */
  199. enum { uppDBStatusProcInfo = 0x000FAA90 };                         /* pascal 1_byte Func(2_bytes, 2_bytes, 2_bytes, 2_bytes, 2_bytes, 4_bytes, 4_bytes) */
  200. enum { uppDBResultHandlerProcInfo = 0x0003EAE0 };                 /* pascal 2_bytes Func(4_bytes, 2_bytes, 2_bytes, 2_bytes, 4_bytes, 4_bytes) */
  201. #define NewDBCompletionProc(userRoutine)                         (DBCompletionUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBCompletionProcInfo, GetCurrentArchitecture())
  202. #define NewDBQueryDefProc(userRoutine)                             (DBQueryDefUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBQueryDefProcInfo, GetCurrentArchitecture())
  203. #define NewDBStatusProc(userRoutine)                             (DBStatusUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBStatusProcInfo, GetCurrentArchitecture())
  204. #define NewDBResultHandlerProc(userRoutine)                     (DBResultHandlerUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBResultHandlerProcInfo, GetCurrentArchitecture())
  205. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  206.     #pragma parameter CallDBCompletionProc(__A0, __A1)
  207.     void CallDBCompletionProc(DBCompletionUPP routine, DBAsyncParmBlkPtr pb) = 0x4E90;
  208. #else
  209.     #define CallDBCompletionProc(userRoutine, pb)                 CALL_ONE_PARAMETER_UPP((userRoutine), uppDBCompletionProcInfo, (pb))
  210. #endif
  211. #define CallDBQueryDefProc(userRoutine, sessID, query)             CALL_TWO_PARAMETER_UPP((userRoutine), uppDBQueryDefProcInfo, (sessID), (query))
  212. #define CallDBStatusProc(userRoutine, message, result, dataLen, dataPlaces, dataFlags, dataType, dataPtr)  CALL_SEVEN_PARAMETER_UPP((userRoutine), uppDBStatusProcInfo, (message), (result), (dataLen), (dataPlaces), (dataFlags), (dataType), (dataPtr))
  213. #define CallDBResultHandlerProc(userRoutine, dataType, theLen, thePlaces, theFlags, theData, theText)  CALL_SIX_PARAMETER_UPP((userRoutine), uppDBResultHandlerProcInfo, (dataType), (theLen), (thePlaces), (theFlags), (theData), (theText))
  214. EXTERN_API( OSErr )
  215. InitDBPack                        (void)                                                        FIVEWORDINLINE(0x3F3C, 0x0004, 0x303C, 0x0100, 0xA82F);
  216.  
  217. EXTERN_API( OSErr )
  218. DBInit                            (long *                    sessID,
  219.                                  ConstStr63Param         ddevName,
  220.                                  ConstStr255Param         host,
  221.                                  ConstStr255Param         user,
  222.                                  ConstStr255Param         passwd,
  223.                                  ConstStr255Param         connStr,
  224.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0E02, 0xA82F);
  225.  
  226. EXTERN_API( OSErr )
  227. DBEnd                            (long                     sessID,
  228.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0403, 0xA82F);
  229.  
  230. EXTERN_API( OSErr )
  231. DBGetConnInfo                    (long                     sessID,
  232.                                  short                     sessNum,
  233.                                  long *                    returnedID,
  234.                                  long *                    version,
  235.                                  Str63                     ddevName,
  236.                                  Str255                 host,
  237.                                  Str255                 user,
  238.                                  Str255                 network,
  239.                                  Str255                 connStr,
  240.                                  long *                    start,
  241.                                  OSErr *                state,
  242.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x1704, 0xA82F);
  243.  
  244. EXTERN_API( OSErr )
  245. DBGetSessionNum                    (long                     sessID,
  246.                                  short *                sessNum,
  247.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0605, 0xA82F);
  248.  
  249. EXTERN_API( OSErr )
  250. DBSend                            (long                     sessID,
  251.                                  Ptr                     text,
  252.                                  short                     len,
  253.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0706, 0xA82F);
  254.  
  255. EXTERN_API( OSErr )
  256. DBSendItem                        (long                     sessID,
  257.                                  DBType                 dataType,
  258.                                  short                     len,
  259.                                  short                     places,
  260.                                  short                     flags,
  261.                                  void *                    buffer,
  262.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0B07, 0xA82F);
  263.  
  264. EXTERN_API( OSErr )
  265. DBExec                            (long                     sessID,
  266.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0408, 0xA82F);
  267.  
  268. EXTERN_API( OSErr )
  269. DBState                            (long                     sessID,
  270.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0409, 0xA82F);
  271.  
  272. EXTERN_API( OSErr )
  273. DBGetErr                        (long                     sessID,
  274.                                  long *                    err1,
  275.                                  long *                    err2,
  276.                                  Str255                 item1,
  277.                                  Str255                 item2,
  278.                                  Str255                 errorMsg,
  279.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0E0A, 0xA82F);
  280.  
  281. EXTERN_API( OSErr )
  282. DBBreak                            (long                     sessID,
  283.                                  Boolean                 abort,
  284.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x050B, 0xA82F);
  285.  
  286. EXTERN_API( OSErr )
  287. DBGetItem                        (long                     sessID,
  288.                                  long                     timeout,
  289.                                  DBType *                dataType,
  290.                                  short *                len,
  291.                                  short *                places,
  292.                                  short *                flags,
  293.                                  void *                    buffer,
  294.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x100C, 0xA82F);
  295.  
  296. EXTERN_API( OSErr )
  297. DBUnGetItem                        (long                     sessID,
  298.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x040D, 0xA82F);
  299.  
  300. EXTERN_API( OSErr )
  301. DBKill                            (DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x020E, 0xA82F);
  302.  
  303. EXTERN_API( OSErr )
  304. DBGetNewQuery                    (short                     queryID,
  305.                                  QueryHandle *            query)                                THREEWORDINLINE(0x303C, 0x030F, 0xA82F);
  306.  
  307. EXTERN_API( OSErr )
  308. DBDisposeQuery                    (QueryHandle             query)                                THREEWORDINLINE(0x303C, 0x0210, 0xA82F);
  309.  
  310. EXTERN_API( OSErr )
  311. DBStartQuery                    (long *                    sessID,
  312.                                  QueryHandle             query,
  313.                                  DBStatusUPP             statusProc,
  314.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0811, 0xA82F);
  315.  
  316. EXTERN_API( OSErr )
  317. DBGetQueryResults                (long                     sessID,
  318.                                  ResultsRecord *        results,
  319.                                  long                     timeout,
  320.                                  DBStatusUPP             statusProc,
  321.                                  DBAsyncParmBlkPtr         asyncPB)                            THREEWORDINLINE(0x303C, 0x0A12, 0xA82F);
  322.  
  323. EXTERN_API( OSErr )
  324. DBResultsToText                    (ResultsRecord *        results,
  325.                                  Handle *                theText)                            THREEWORDINLINE(0x303C, 0x0413, 0xA82F);
  326.  
  327. EXTERN_API( OSErr )
  328. DBInstallResultHandler            (DBType                 dataType,
  329.                                  DBResultHandlerUPP     theHandler,
  330.                                  Boolean                 isSysHandler)                        THREEWORDINLINE(0x303C, 0x0514, 0xA82F);
  331.  
  332. EXTERN_API( OSErr )
  333. DBRemoveResultHandler            (DBType                 dataType)                            THREEWORDINLINE(0x303C, 0x0215, 0xA82F);
  334.  
  335. EXTERN_API( OSErr )
  336. DBGetResultHandler                (DBType                 dataType,
  337.                                  DBResultHandlerUPP *    theHandler,
  338.                                  Boolean                 getSysHandler)                        THREEWORDINLINE(0x303C, 0x0516, 0xA82F);
  339.  
  340. EXTERN_API( OSErr )
  341. DBIdle                            (void)                                                        THREEWORDINLINE(0x303C, 0x00FF, 0xA82F);
  342.  
  343.  
  344.  
  345.  
  346. #if PRAGMA_STRUCT_ALIGN
  347.     #pragma options align=reset
  348. #elif PRAGMA_STRUCT_PACKPUSH
  349.     #pragma pack(pop)
  350. #elif PRAGMA_STRUCT_PACK
  351.     #pragma pack()
  352. #endif
  353.  
  354. #ifdef PRAGMA_IMPORT_OFF
  355. #pragma import off
  356. #elif PRAGMA_IMPORT
  357. #pragma import reset
  358. #endif
  359.  
  360. #ifdef __cplusplus
  361. }
  362. #endif
  363.  
  364. #endif /* __DATABASEACCESS__ */
  365.  
  366.